﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace eLearning.Business
{
    public class LibraryItemsRepository
    {
        // Create an instance of entities framework
        eLearningEntities entities = new eLearningEntities();
        public List<LibraryItem> GetAll(int libraryId)
        {
            return (from c in entities.LibraryItems where c.LibraryId == libraryId select c).ToList();
        }
        public List<LibraryItem> GetAll()
        {
            return (from c in entities.LibraryItems select c).ToList();
        }
        public LibraryItem GetSingle(int id)
        {
            return (from c in entities.LibraryItems where c.ItemId == id select c).FirstOrDefault();
        }
        public void Create(LibraryItem _object)
        {
            entities.AddToLibraryItems(_object);
            entities.SaveChanges();
        }
        public void Update(LibraryItem _object)
        {
            entities.SaveChanges();
        }
        public void Delete(int id)
        {
            var _object = (from _list in entities.LibraryItems where _list.ItemId == id select _list).First();
            entities.DeleteObject(_object);
            entities.SaveChanges();
        }
    }
}